<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class HostController extends Controller
{
    //展示医院列表 
    public  function index(Request $request)
    {
        $city_id  = request('city_id','');
       if(!empty($city_id)){
                         $list =  \DB::table('hos_list')
                            ->select('id','hos_name','hos_img','hos_linimg','province')
                            ->where('hos_del','=',0)
                            ->get();
                    $list = json_decode(json_encode($list),true);
                    $data = array(
                             'data'=>$list,  
                    );
                    return $data;
           
       }else{
                      //如果城市ID不存在 那么进行随机查询
                    $list =  \DB::table('hos_list')
                            ->select('id','hos_name','hos_img','hos_linimg','province')
                            ->where('hos_del','=',0)
                            ->get();
                      //$list = \DB::select("select type.* from type where city_id = $city_id order by concat(type.path,type.id) asc");
                    $list = json_decode(json_encode($list),true);
                    $data = array(
                         'data'=>$list,  
                    );
                    return $data;
                    
       }
    }
    
    //展示某些医院下推荐的专家
    public function indexys(Request $request)
    {
        $city_id = request('city_id','');
        if(!empty($city_id)){
                   $info = DB::table('type_info')
                             ->select('type_info.id','type_info.name','type_info.job','type_info.content','type_info.head_img','type_info.num','type_info.honor_1','type_info.honor_2','type_info.hos_id')
                              ->leftJoin('hos_list','type_info.hos_id','=','hos_list.id')
                              ->where('type_info.is_del','=',0)
                              ->where('type_info.is_top','=',1)
                              ->where('type_info.city_id','=',$city_id)
                              ->get();
                  $list  = json_decode(json_encode($info,true));
                  $data = array(
                      'data'=>$list,
                  );
                  return $data;
        }else{
              $info = DB::table('type_info')
                                ->select('type_info.id','type_info.name','type_info.job','type_info.content','type_info.head_img','type_info.num','type_info.honor_1','type_info.honor_2','type_info.hos_id')
                              ->leftJoin('hos_list','type_info.hos_id','=','hos_list.id')
                              ->where('type_info.is_del','=',0)
                              ->where('type_info.is_top','=',1)
                              ->get();
                  $list  = json_decode(json_encode($info,true));
                  $data = array(
                      'data'=>$list,
                  );
                  return $data;
        }
      
    }
    
    //医生详情
    public  function indexysxq(Request $request)
    {
        $id = request('id','');
        if(!empty($id)){
            $info  = DB::table('type_info')->select('name','job','content','head_img','num','honor_1','honor_2','hos_id')->where('id',$id)->get();
            $list = json_decode(json_encode($info,true));
            $data =  array(
              'data'=>$list,  
            );
            
            return $data;
        }else{
            return $msg = array(
                   'status'=>'000',
                   'message'=>'ID不存在',
            );
        }
    }
    
    
    
    
    
    //文章  
    public  function  wenzhang(Request $request)
    {
        $info  = DB::table('article')
                ->select('id','title','guanggao_img')
                ->get();
        $list = json_decode(json_encode($info,true));
        $data  = array(
            'list'=>$list,
          
        );
        if($data){
             return $data;
        }else{
            return $msg = array(
                'status'=>'200',
                'message'=>'暂时没有文章',
            );
        }
    }
    
    //文章详情
    public function wenzhangxq(Request $request)
    {
        $id = request('id','');
        $info  = DB::table('article')
                ->where('id',$id)
                ->get();
        $list = json_decode(json_encode($info,true));
        $data  = array(
            'list'=>$list,
        );
        if($data){
             return $data;
        }else{
            return $msg = array(
                'status'=>'200',
                'message'=>'ID不存在',
            );
        }
    }
    
    
    
    //活动详情
    public function huodong(Request $request)
    {
        $info  = DB::table('activity')->select('title','name','created_at','img','id','href')->get();
        $list = json_decode(json_encode($info,true));
        $data  = array(
            'list'=>$list,
        );
        if($data){
             return $data;
        }else{
            return $msg = array(
                'status'=>'200',
                'message'=>'活动不存在',
            );
        }
        
    }
    
    
    public function huodongxq(Request $request)
    {
        $info = DB::table('activity')->where('id',$id)->first();
          $list = json_decode(json_encode($info,true));
        $data  = array(
            'list'=>$list,
        );
        if($data){
             return $data;
        }else{
            return $msg = array(
                'status'=>'200',
                'message'=>'活动不存在',
            );
        }
    }
    
    
    public function href(Request $request)
    {
        $info = DB::table('activity')->where('is_top',1)->select('id','img','href')->first();
        $list = json_decode(json_encode($info,true));
        $data  = array(
            'list'=>$list,
        );
        if($data){
             return $data;
        }else{
            return $msg = array(
                'status'=>'200',
                'message'=>'活动不存在',
            );
        }
    }
    
    
}
